using System;
using System.IO;
using PTP.Core;

namespace PTP.Devices
{
  /// <summary>
  /// Adapter for Canon EOS digital camera. Register this adapter to DeviceFactory object.
  /// </summary>
  public class CanonEOSAdapter : IDeviceAdapter
  {
    public bool IsValidForDevice(DeviceInfo info)
    {
      if (info == null)
        throw new ArgumentNullException("info");

      if (info.Model == null)
        return false;

      // quick solution is to look Model.. VendorExtensionID is microsoft.
      // libgphoto seems to use USB device vendor and model to identify camera
      return info.Model.IndexOf("Canon EOS") > -1; 
    }

    public IPTPDevice CreateDevice(ContainerStream s)
    {
      return new CanonEOS(s, true);
    }
  }

  /// <summary>
  /// Canon EOS spesific commands
  /// </summary>
  public enum CanonEosCommands
  {
    GetEvent = 0x9116,
    RemoteRelease = 0x910F,
    RemoteReleaseOn = 0x9128,
    RemoteReleaseOff = 0x9129,
    KeepDeviceOn = 0x911D,
    GetViewFinderData = 0x9153,
    SetDevicePropValueEx = 0x9110,
    SetRemoteMode = 0x9114,
    SetEventMode = 0x9115
  }

  /// <summary>
  /// Canon EOS digital camera
  /// </summary>
  public class CanonEOS : PTPDeviceBase
  {


    public CanonEOS(ContainerStream stream, bool sendKeepDeviceOn)
      : base(stream)
    {
      //TODO: turn LCD off and start sending KeepDeviceOn messages

    }

    public void KeepDeviceOn()
    {
      CommandBlockContainer command = new CommandBlockContainer((int)CanonEosCommands.KeepDeviceOn);
      sendCommand(command, true, null);
    }

    public void InitiateCapture()
    {
      throw new NotImplementedException();
    }

    public void InitiateCapture(int storageID, int objectFormat)
    {
      throw new NotImplementedException();
    }

    public void SelfTest()
    {
      CommandBlockContainer command = new CommandBlockContainer((int)CommandCode.SelfTest);
      sendCommand(command, true, null);
    }
  }
}
